package com.library.search.service;

import com.library.entity.StaffSearch;
import com.library.search.dao.SearchDaoImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
@Transactional(readOnly=false)
public class SearchServiceImpl {
	
	@Resource
	private SearchDaoImpl searchDaoImpl;

	public void addSearch(StaffSearch search){
		this.searchDaoImpl.saveSearch(search);
	}

    @Transactional(readOnly=true)
	public StaffSearch getSearchById(Integer searchId)
	{
		return this.searchDaoImpl.getSearchById(searchId);
	}

	//精确查找
	@Transactional(readOnly=true)
	public StaffSearch getSearchByKey(String key)
	{
		return this.searchDaoImpl.getSearchByKey(key);
	}

	//模糊查找
	@Transactional(readOnly=true)
	public List<StaffSearch> getSearchByKeyVague(String key)
	{
		return this.searchDaoImpl.getSearchByKeyVague(key);
	}

	public void updateSearch(StaffSearch search){
		this.searchDaoImpl.updateSearch(search);
	}

    @Transactional(readOnly=true)
	/*查找全部评价记录 按搜索次数降序*/
	public List<StaffSearch> getAllSearch()
	{
		return this.searchDaoImpl.getAllOrderBySearchCount();
	}

	@Transactional(readOnly=true)
	/*查找热门评价记录 按搜索次数降序*/
	public List<StaffSearch> getHotSearch(int num)
	{
		return this.searchDaoImpl.getHotOrderBySearchCount(num);
	}

	/*查询数量*/
	@Transactional(readOnly=true)
	public Long getStaffSearchsCountByParams(Map paramsMap){
		return this.searchDaoImpl.findCountByProperty(paramsMap);
	}

	/*删除指定评价记录*/
	public void deleteSearch(int searchId){
		StaffSearch s = this.getSearchById(searchId);
		this.searchDaoImpl.deleteSearch(s);
    }
}
